package sc.math;

public final class BezierCurve implements CubicCurve {

    /**
     * Given the four control points a, b, c and d, Cubic Bezier curves pass
     * through a and d, with b effecting the curve as it leaves a and c
     * effecting the curve as it approaches d.
     * 
     * @param i
     * 		Interval along curve [0, 1]
     * 
     * @return the interval between a and d
     */
    public double interval(double a, double b, double c, double d, double i) {
        return a + //
                i * (-a * 3 + i * (3 * a - a * i)) + //
                i * (3 * b + i * (-6 * b + b * 3 * i)) + //
                i * i * (c * 3 - c * 3 * i) + d * i * i * i;
    }
    
    /**
     * Gets the index of the control point from where the curve starts.
     * 
     * This is a fairly pointless method, only needed to enable a generic
     * Spline2D. A BezierCurve starts at the first control point, so this
     * method returns 0.
     * 
     * @return index of the control point from where the curve starts
     */
    public int startIndex() {
        return 0;
    }
    
    /**
     * Gets the index of the control point from where the curve ends.
     * 
     * This is a fairly pointless method, only needed to enable a generic
     * Spline2D. A BezierCurve ends at the last control point, so this
     * method returns 3.
     * 
     * @return index of the control point from where the curve ends
     */
    public int endIndex() {
        return 3;
    }
    
}
